package org.xdq.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xdq.demo.dao.EmpDao;
import org.xdq.demo.dto.EmpDto;
import org.xdq.demo.dto.EmpQueryDto;
import org.xdq.demo.service.MyService;
import org.xdq.demo.util.MyUtils;

import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class MyServiceImpl implements MyService {

    @Autowired
    private EmpDao empDao;


    @Override
    public void saveSomeEmps(EmpDto... dtos) {
        for(EmpDto dto : dtos){
            empDao.insertNewEmp(dto);
        }
        //throw new RuntimeException("测试");
    }

    @Override
    public Map<String, Object> getEmpPage(EmpQueryDto dto)  {
        try {
            return MyUtils.getPage(dto,()->empDao.findEmpList(dto));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
